/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fri.businessLayer;

import fri.entiry.FrCurrency;
import java.util.List;
import java.util.Vector;
import javax.ejb.Stateless;
import javax.persistence.Query;

/**
 *
 * @author NguyenDongUIT
 */
@Stateless
public class CurrencyBean extends GenericDAO<FrCurrency> implements CurrencyBeanRemote {

    public CurrencyBean() {
        super(FrCurrency.class);
    }
    
    

    public CurrencyBean(Class<FrCurrency> entityClass) {
        super(entityClass);
    }


    @Override
    public List<FrCurrency> getAllCurrency() {
        try {
            Query q = em.createQuery("SELECT s FROM FrCurrency s");
            List<FrCurrency> result = (List<FrCurrency>) q.getResultList();
            return result;

        } catch (Exception e) {

            System.out.println("SERVER : ==>" + e.getMessage());
        }

        return null;
    }

    @Override
    public String getNameCurrency(int idCurrency) {
        try {
            FrCurrency item = em.find(FrCurrency.class, idCurrency);
            return item.getCurrencyName();

        } catch (Exception e) {

            System.out.println(e.getMessage());
        }

        return "";
    }

    @Override
    public int addCurrency(FrCurrency currency) {
        return this.save(currency);
    }

    @Override
    public int deleteCurrency(FrCurrency currency) {
        currency.setCurrencyId(currency.getCurrencyId());
        return this.delete(currency);
    }

    @Override
    public FrCurrency getCurrency(int idCurrency) {
        return this.find(idCurrency);
    }

    @Override
    public int updateCurrency(FrCurrency currency) {        
        return this.update(currency);
    }
    
    
    
}
